
_realname=igraph
pkgbase=mingw-w64-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-${_realname}")
pkgver=0.8.3
pkgrel=1
pkgdesc="Library for the analysis of networks (mingw-w64)"
arch=('any')
url="https://igraph.org"
license=('GPL')
source=(https://github.com/igraph/igraph/releases/download/${pkgver}/igraph-${pkgver}.tar.gz
        0001-igraph-0.8.2_foreign.c-fix-newline-on-Windows.patch)
sha256sums=('cc935826d3725a9d95f1b0cc46e3c08c554b29cdd6943f0286d965898120b3f1'
            '1bf512fb6002355b5a0082110095700f386eb9abd1779e0b89822f367bef9c7c')
depends=("${MINGW_PACKAGE_PREFIX}-glpk"
         "${MINGW_PACKAGE_PREFIX}-gmp"
         "${MINGW_PACKAGE_PREFIX}-zlib"
         "${MINGW_PACKAGE_PREFIX}-libxml2")
makedepends=(flex bison)


_srcdir=${_realname}-${pkgver}
_builddir=build-${pkgver}-${MINGW_PACKAGE_PREFIX}

prepare() {
  cd ${_srcdir}

  patch -p1 -i ${srcdir}/0001-igraph-0.8.2_foreign.c-fix-newline-on-Windows.patch

  autoreconf -vfi

  # remove the file testsuite in source tree to force 'make check'
  # to generate it from scratch.
  test -f tests/testsuite || rm -f tests/testsuite
}

build() {
  mkdir -p ${_builddir}
  cd ${_builddir}
  ../${_srcdir}/configure -C \
    --enable-tls             \
    --with-external-glpk     \
    YFLAGS=-Wall \
    igraph_cv_stdout_LF2CRLF=no

  make V=0 || make
}

check() {
  # Redefine function DIFF such that any EOL issues are ignored
  # in tests (by essentially adding the flag '--strip-trailing-cr').
  set -a
  diff_cmd="$(command -v diff)"
  function diff () { "$diff_cmd" --strip-trailing-cr $@ ; }
  set +a

  # igraph 0.8.3: all tests succeeded
  make V=0 -C ${_builddir} check TESTSUITEFLAGS=-j
}

package() {
  make -C ${_builddir} DESTDIR="${pkgdir}" install
  install -D -m644 ${_srcdir}/COPYING "${pkgdir}"/${MSYSTEM_PREFIX}/share/licenses/${_realname}/COPYING
}
